﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace CoreRp
{
    public static class Extensions
    {
        public static string GetCompanyCode(this HttpRequest Request)
        {
            return Request.HttpContext.Session.GetString("COMPANYCODE");
        }
        public static string GetUserCode(this HttpRequest Request)
        {
            return Request.HttpContext.Session.GetString("USERCODE");
        }
        public static string GetRealName(this HttpRequest Request)
        {
            return Request.HttpContext.Session.GetString("REALNAME");
        }
        public static string GetLoginName(this HttpRequest Request)
        {
            return Request.HttpContext.Session.GetString("LOGINNAME");
        }
        public static string GetRoleCode(this HttpRequest Request)
        {
            return Request.HttpContext.Session.GetString("ROLECODE");
        }
        public static string GetRoleName(this HttpRequest Request)
        {
            return Request.HttpContext.Session.GetString("ROLENAME");
        }
        public static string GetNickName(this HttpRequest Request)
        {
            return Request.HttpContext.Session.GetString("NICKNAME");
        }
        /// <summary>
        /// 计算md5的值 (基于UTF-8)
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static string Md5(this string data)
        {
            System.Security.Cryptography.MD5 md5Hasher = System.Security.Cryptography.MD5.Create();
            string strMD5 = Convert.ToBase64String(md5Hasher.ComputeHash(System.Text.Encoding.UTF8.GetBytes(data)));
            return strMD5;
        }
        public static string ToAbsoluteUrl(string url)
        {
            return Services.S_Config.BasePath + url.TrimStart('/');
        }
    }
}
